package com.badibadi.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.sax.StartElementListener;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.AdapterView.OnItemClickListener;

import com.badibadi.activity.AddApplyFormActivity;
import com.badibadi.activity.ShowViewPagerActivity;
import com.badibadi.infos.BrowseAllPhoto_Model;
import com.badibadi.mytools.BitmapHelp;
import com.badibadi.mytools.Constants;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.ShowErWeiMaActivity;
//import com.lidroid.xutils.util.LogUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;

public class GridViewListAdapter extends BaseAdapter {

	private static final String TAG = "GridViewSHUZHUAdapter";
	// FinalBitmap finalBitmap;

	List<String> mList;
	Context context;

	// private DisplayImageOptions options;

	public GridViewListAdapter(Context context, List<String> list) {
		mList = new ArrayList<String>();
		for (int i = 0; i < list.size(); i++)// 去掉所有表情
		{
			// LogUtils.i("我是素哟=》"+mList.get(i));
			// 查到了表情前
			// if(list.get(i).indexOf("//Public/Uploads/")!=-1 ||
			// list.get(i).indexOf("//Public/js/")!=-1)
			if (list.get(i).indexOf(Constants.Fei_biaoqing_qianzui) != -1
					|| list.get(i).indexOf(Constants.Fei_biaoqing_qianzui2) != -1
					|| list.get(i).indexOf(Constants.Fei_biaoqing_qianzui3) != -1
					|| list.get(i).indexOf(Constants.Fei_biaoqing_qianzui4) != -1)
				mList.add(list.get(i));
		}
//		LogUtils.d("列表的大小是：" + mList.size());
		this.context = context;
		// options = new DisplayImageOptions.Builder()
		// .showStubImage(R.drawable.ic_stub)
		// .showImageForEmptyUri(R.drawable.noimage)
		// .showImageOnFail(R.drawable.noimage).cacheInMemory()
		// .cacheOnDisc().displayer(new RoundedBitmapDisplayer(0)).build();
		// finalBitmap=FinalBitmap.create(this.context);
		// finalBitmap.configLoadfailImage(R.drawable.noimage);
	}

	// public GridViewListAdapter(Context context, String[] picture) {
	// pic = picture;
	// this.context = context;
	// options = new DisplayImageOptions.Builder()
	// .showStubImage(R.drawable.ic_stub)
	// .showImageForEmptyUri(R.drawable.noimage)
	// .showImageOnFail(R.drawable.noimage).cacheInMemory()
	// .cacheOnDisc().displayer(new RoundedBitmapDisplayer(0)).build();
	// }

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	// public String getItemIdtoString(int position) {
	// return ("" + picId[position]);
	// }

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater ll = LayoutInflater.from(context);
		convertView = ll.inflate(R.layout.net_img1_img, null);
		ImageView iv = (ImageView) convertView.findViewById(R.id.img);
		// iv.setLayoutParams(new
		// LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));
//		LogUtils.d("mlist====>" + mList.get(position));
		if (!mList.get(position).startsWith("http")) {
			if (mList.get(position).startsWith("//Public/Uploads/")) {
				try {
					// ImageLoader.getInstance()
					// .displayImage(
					// Constants.BadiDownImgUrl + "/"
					// + mList.get(position)
					// + Constants.App9block, iv, options);

					new BitmapHelp()
							.displayImage(context, iv, Constants.BadiDownImgUrl
									+ "/" + mList.get(position)
									+ Constants.App9block);
				} catch (Exception e) {
					// TODO: handle exception
				}
				// iv.setOnClickListener(new View.OnClickListener() {
				//
				// @Override
				// public void onClick(View v) {
				// // TODO Auto-generated method stub
				// Intent intent = new Intent(context,
				// ShowBigPicActivity.class);
				// intent.putExtra("pic", Constants.BadiDownImgUrl + "/"
				// + mList.get(position));
				// context.startActivity(intent);
				// }
				// });
				iv.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(context,
								ShowViewPagerActivity.class);
						intent.putStringArrayListExtra("pic",
								(ArrayList<String>) mList);
						intent.putExtra("position", position);
						context.startActivity(intent);
					}
				});
			} else // if(mList.get(position).startsWith("//Public/js/"))
			{
				try {
					// ImageLoader.getInstance()
					// .displayImage(
					// Constants.BadiWebImgUrl + "/"
					// + mList.get(position), iv, options);
					new BitmapHelp()
							.displayImage(context, iv, Constants.BadiWebImgUrl
									+ "/" + mList.get(position));

				} catch (Exception e) {
					// TODO: handle exception
				}
				iv.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(context,
								ShowViewPagerActivity.class);
						intent.putStringArrayListExtra("pic",
								(ArrayList<String>) mList);
						intent.putExtra("position", position);
						context.startActivity(intent);
					}
				});
			}

		} else {
			try {
				// ImageLoader.getInstance().displayImage(mList.get(position),
				// iv,
				// options);
				new BitmapHelp().displayImage(context, iv, mList.get(position));
				iv.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent intent = new Intent(context,
								ShowViewPagerActivity.class);
						intent.putStringArrayListExtra("pic",
								(ArrayList<String>) mList);
						intent.putExtra("position", position);
						context.startActivity(intent);
					}
				});

			} catch (Exception e) {
				// TODO: handle exception
			}
		}

		// try {
		// VolleyTools.displayImageByNetworkImageView(context,
		// Constants.BadiDownImgUrl+"/"+pic[position], iv);
		// } catch (Exception e) {
		// // TODO: handle exception
		// }

		return convertView;
	}

}
